#include "KeyHandler.h"
#include "../Game.h" 

#include "IrrNewt.hpp"

KeyHandler::KeyHandler() {
}

KeyHandler::~KeyHandler() {
}

bool KeyHandler::OnEvent(const SEvent& event) {
	if(Game::s_CameraBody)
		Game::s_CameraBody->OnEvent(event);
	if(event.EventType == EET_KEY_INPUT_EVENT) {
		if(!event.KeyInput.PressedDown) {
			switch(event.KeyInput.Key) {
				case irr::KEY_KEY_D:
				case irr::KEY_KEY_S:
				case irr::KEY_KEY_W:
				case irr::KEY_KEY_A: {
					Game::s_Player->handleInput(event.KeyInput.Key, false);
					return true;
				}
				break;
				case irr::KEY_LEFT:
				case irr::KEY_RIGHT: {
					Game::s_rot = 0.0f;
				}
				default: {
				}
			}
//			if(event.KeyInput.Key == irr::KEY_UP) {
//				Game::s_CameraBody->addForce(Game::s_CameraBody->getRotationBody()*1.0f);
//			}
//			if(event.KeyInput.Key == irr::KEY_DOWN) {
//				Game::s_CameraBody->addForce(Game::s_CameraBody->getRotationBody()*-1.0f);
//			}
		} else {
			switch(event.KeyInput.Key) {
				case irr::KEY_KEY_D:
				case irr::KEY_KEY_S:
				case irr::KEY_KEY_W:
				case irr::KEY_KEY_A: {
					Game::s_Player->handleInput(event.KeyInput.Key, true);
					return true;
				}
				break;
				case irr::KEY_KEY_Q: {
					Game::Quit();
					return true;
				}
				break;
				case irr::KEY_KEY_P: {
					irr::core::vector3df posit = Game::camera->getPosition();
					std::cout<<"Position is: "<<std::endl;
					std::cout<<"X: "<<posit.X<<std::endl;
					std::cout<<"Y: "<<posit.Y<<std::endl;
					std::cout<<"Z: "<<posit.Z<<std::endl;
					return true;
				}
				break;
				case irr::KEY_LEFT: {
					Game::s_rot = -1.0f;
				}
				break;
				case irr::KEY_RIGHT: {
					Game::s_rot = 1.0f;
				}
				break;
				default: {
				}
				//handleInput(event);
			}
		}
	}
	return false;
}